<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:widget="http://www.netvibes.com/ns/">
<head>
	<title>历史上的今天</title>
	<link rel="icon" href="http://www.nlc.gov.cn/css/favicon.ico" type="image/x-icon" />
	<meta name="title" content="历史上的今天" />
	<meta name="author" content="ehaagwlke" />
	<meta name="website" content="http://www.nlc.gov.cn" />
	<meta name="description" content="历史上的今天，数据来自国家图书馆网站" />
	<meta name="version" content="alpha" />
	<meta name="keyword" content="历史上的今天" />
	<meta name="thumbnail" content="http://ehaagwlke.googlepages.com/tih-thumbnail.jpg" />
	<meta name="screenshot" content="http://ehaagwlke.googlepages.com/tih.png" />
	<meta name="debugMode" content="true" />


	
	<widget:preferences>
		<preference type="text" name="title" label="标题" onchange="true"  />
		<preference type="text" name="items" label="显示条数" onchange="true" />
	</widget:preferences>

	<style type="text/css" media="screen">
		ul { list-style-type:disc;; }
		li span{ float:right;}
		.sad{  font-weight:normal; }
		.sad a{ color:#fff; background-color: #000; font-weight:bold;}
	</style>

	<script type="text/javascript">
		//<![CDATA[
			
			var opContent = ''; //variable hold the content that to be displayed
			var itemNum = '';   //variable hold the amount of items that to displayed, max is 50, default is 10.
			
			
			widget.dataInt = function() {
				UWA.Data.getXml(
					'http://www.nlc.gov.cn/rss/lishi.xml',
					widget.dataProcessor
					);
			}
		
			
		
			widget.dataProcessor = function(xml) {
				//set the number of items to be displayed
				if(widget.getValue("items")){			
					itemNum = widget.getValue("items");
				}
				
				
				widget.setBody('<ul class="text_list"></ul>');
				var el = UWA.$element(widget.body.getElementsByTagName('ul')[0]);
				var w = el.getDimensions().width;
				
				titleLen = Math.floor(w*0.8/14);
				
				var rootNode = xml.documentElement;
				
				var contentItems = rootNode.getElementsByTagName('item');
				
				//calculate the max of items to be displayed
				if(itemNum && itemNum <= 50 && itemNum > 0 ) {
					var itemMaxNum = itemNum;
				}else{
					var itemMaxNum = 10;
				}

				//extract the contents from the xml document
				for(i=0;i<itemMaxNum;i++){

						var title = contentItems[i].getElementsByTagName("title")[0].firstChild.nodeValue;
						var time = contentItems[i].getElementsByTagName('pubDate')[0].firstChild.nodeValue;
						var link = contentItems[i].getElementsByTagName('link')[0].firstChild.nodeValue;
						var description = contentItems[i].getElementsByTagName('description')[0].firstChild.nodeValue;
					
						var opTime = time.substr(5,6);
						
						if(title.length > titleLen) { var nTitle = title.substr(0,titleLen-1)+'...';} else { var nTitle = title; }
						
						
						//append some special style to some bad news
						if(title.indexOf("逝世") != -1){ var specialStyle=' class="sad"'; }else{ var specialStyle=''; }
						
						opContent += '<li'+specialStyle+'><span>'+opTime+'</span><a href="'+link+'" title="'+title+'" target="_blank">'+nTitle+'</a></li>';
				}

				opContent += '<p style="float:right;border-bottom:1px dashed"><a href="http://www.nlc.gov.cn/GB/channel55/56/index.html" target="_blank">数据来源</a></p>'
			
				if(widget.getValue("title")){
					var title = widget.getValue("title");
					widget.setTitle(title);
				}else{
					widget.setTitle("历史上的今天");
				}
			
				el.innerHTML = opContent;
				
			}
			
			widget.onLoad = function(){
				widget.dataInt();
			}
			
			widget.onRefresh = function() {
				opContent = ''
				widget.dataInt();
			}

			widget.onResize = function(){
				opContent = ''
				widget.dataInt();
			}
			
		//]]>
	</script>
</head>
<body>
	
	<div class="content">数据读取中，敬请耐心等待.....</div>
	

</body>
</html>
